#ifndef _ATOMIC_0804_DDPC_H_
#define _ATOMIC_0804_DDPC_H_

/*------------------------ Include Begin --------------------------*/

// C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <time.h>
#include <ctype.h>

// C++
#include <iostream>
#include <fstream>
#include <chrono>
#include <string>
#include <random>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stdbool.h>
#include <sstream>

/*------------------------  Include End  -------------------------*/

/*------------------------  Service Info Begin  --------------------------*/
/**
 *
 * @name:     atomic_0804_ddpc
 * @chinese_name: 弹道偏差计算
 * @description: information atomic_0804_ddpc
 * @version: V1.0.0
 * @build_time: 2024-05-23 16:00:00
 * @license: MIT
 * @service_path: atomic_0804_ddpc
 *
 * @resource_requirement:
 *         + cpu_architecture: x86_64
 *         + memory: 4GB
 *         + hard_disk: 50GB
 *
 * @developer:
 *      +name: Spiderman
 *      +email: Spidermsan@atomic_0804_ddpc.com
 * @maintainer:
 *      +name: yishui
 *      +email:yishui@atomic_0804_ddpc.com
 * @operating_system:
 *      +name:Linux
 *      +v1:5.13.0-117-generic
 *      +v2:5.14.0-117-generic
 *      +name:SylixOS
 *      +v1:1.0.0
 *      +v2:1.0.2
 *
 *
 *
 */
/*------------------------  Service Info End  --------------------------*/

/*------------------------  Return Type Begin  --------------------------*/

#define ATOMIC_SERVICE_SUCCESS 0
#define ATOMIC_SERVICE_FAIL -1
#define ATOMIC_SERVICE_TIMEOUT -2
#define ATOMIC_SERVICE_ERROR -3
#define ATOMIC_SERVICE_NOT_SUPPORT -4
#define ATOMIC_SERVICE_NOT_READY -5
#define ATOMIC_SERVICE_NOT_INIT -6
#define ATOMIC_SERVICE_NOT_START -7
#define ATOMIC_SERVICE_NOT_STOP -8
#define ATOMIC_SERVICE_NOT_RELEASE -9
#define ATOMIC_SERVICE_NOT_DESTROY -10
#define ATOMIC_SERVICE_NOT_CREATE -11
#define ATOMIC_SERVICE_NOT_OPEN -12
#define ATOMIC_SERVICE_NOT_CLOSE -13
#define ATOMIC_SERVICE_NOT_READ -14
#define ATOMIC_SERVICE_NOT_WRITE -15
#define ATOMIC_SERVICE_NOT_SEEK -16
#define ATOMIC_SERVICE_NOT_TELL -17
#define ATOMIC_SERVICE_NOT_SIZE -18
#define ATOMIC_SERVICE_NOT_SEEK_END -19
#define ATOMIC_SERVICE_NOT_SEEK_SET -20
#define ATOMIC_SERVICE_NOT_SEEK_CUR -21
#define ATOMIC_SERVICE_NOT_SEEK_ABS -22

/*------------------------  Return Type End  --------------------------*/

/*------------------------  Message Info Begin  --------------------------*/

// 弹道偏差计算输入参数 (基本数据类型)
typedef struct
{
    double missile_velocity;        // 导弹速度(m/s)
    double missile_altitude;        // 导弹高度(m)
    double missile_angle;           // 导弹角度(度)
    double waypoint1_lat;           // 导弹纬度
    double waypoint1_lon;           // 导弹经度
    double target_velocity;         // 目标速度(m/s)
    double target_altitude;         // 目标高度(m)
    double target_angle;            // 目标角度(度)
    double waypoint2_lat;           // 目标纬度
    double waypoint2_lon;           // 目标经度
    double estimated_time;          // 预计到达时间(s)
    double filtered_acceleration_z; // 最大加速度(m/s²)
    double max_deviation;           // 最小转弯半径(m)
    double timestamp;               // 时间戳(s)
} TrajectoryDeviationInput;

// 弹道偏差计算输出参数 (基本数据类型)
typedef struct
{
    double velocity_deviation;      // 速度偏差(m/s)
    double altitude_deviation;      // 高度偏差(m)
    double angle_deviation;         // 角度偏差(度)
    double lateral_deviation;       // 横向偏差(m)
    double longitudinal_deviation;  // 纵向偏差(m)
    double time_deviation;          // 时间偏差(s)
    double predicted_miss_distance; // 预测脱靶量(m)
    double max_acceleration;        // 所需加速度(m/s²)
    double max_turn_rate;           // 所需转弯率(度/s)
    double time_to_target;          // 偏差评分
    double missile_velocity;        // 速度修正量(m/s)
    double missile_altitude;        // 高度修正量(m)
    double missile_angle;           // 角度修正量(度)
    double optimal_path_length;     // 最优路径长度(m)
    double current_path_length;     // 当前路径长度(m)
    double dt;                      // 路径效率(0-1)
    double energy_consumption;      // 能量消耗估计
    double risk_factor;             // 风险因子(0-1)
} TrajectoryDeviationOutput;

/*------------------------  Message Info End  --------------------------*/

// 三维向量结构
typedef struct
{
    double x, y, z;
} Vector3D;

/*------------------------  Interface Declaration Begin  --------------------------*/

// 弹道偏差计算函数
int calculateTrajectoryDeviation(TrajectoryDeviationInput *input, TrajectoryDeviationOutput *output);

/*------------------------  Interface Declaration End  --------------------------*/

// 计算两点之间的距离
double haversineDistance(double lat1, double lon1, double lat2, double lon2);
// 计算两点之间的方位角
double calculateBearing(double lat1, double lon1, double lat2, double lon2);
// 向量叉积
Vector3D crossProduct(Vector3D a, Vector3D b);
// 向量点积
double dotProduct(Vector3D a, Vector3D b);
// 向量长度
double vectorLength(Vector3D v);
// 归一化向量
Vector3D normalizeVector(Vector3D v);

#endif // _ATOMIC_0804_DDPC_H_
